/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.verify.constraint;

import picounit.features.verify.Evaluator;
import picounit.verify.ReasonCapturer;
import picounit.verify.constraint.Constraint;

public class EvaluatingReasonCapturer implements ReasonCapturer {
	private final Evaluator evaluator;
	private final Constraint constraint;
	private final Stringer stringer;

	public EvaluatingReasonCapturer(Evaluator evaluator, Constraint constraint) {
		this(evaluator, constraint, null);
	}

	public EvaluatingReasonCapturer(Evaluator evaluator, Constraint constraint, Stringer stringer) {
		this.evaluator = evaluator;
		this.constraint = constraint;
		this.stringer = stringer;
	}

	public void because(String reason) {
		evaluator.setReason(reason);

		if (stringer != null) {
			evaluator.evaluate(constraint, stringer);
		}
		else {
			evaluator.evaluate(constraint);
		}
	}
}
